package net.aiotos.common.util;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ArgsParser {
    @Parameter(names = {"-h", "--h"}, description = "中台接口地址", order = 4)
    String host = "http://sys.iotos.net.cn";
    // version default is false
    @Parameter(names = {"-u", "--u"}, description = "中台登录帐号", order = 0, required = true, arity = 1)
    String username = null;
    // proxy default is true
    @Parameter(names = {"-p", "--p"}, description = "中台帐号密码", order = 1, required = true)
    String password = null;
    @Parameter(names = {"-i", "--i"}, description = "中台网关uuid", order = 1, required = true)
    String uuid = null;
    /**
     * 激活服务的名称
     */
    @Parameter(names = {"-e", "--e"}, description = "服务名称", order = 5, required = false)
    private String env = "default";
    private JCommander jc = null;
    public ArgsParser parse(String[] args) {
        ArgsParser options = new ArgsParser();
        jc = JCommander.newBuilder().addObject(options).build();
        try {
            jc.parse(args);
        } catch (Exception parameterException) {
            throw parameterException;
        }
        return options;
    }

    public void getUsage() {
        if(jc == null) return;
        jc.usage();
    }
}
